module ysyx_22040213_memory  (
	  input [63:0] mwdata,
	  input [63:0] maddr,
	  input [2:0]funct3,
//	  input [63:0] mraddr,
	  input lm_en,
	  input sm_en,
	  output reg [63:0] mrdata
);

	import "DPI-C" function void mpmem_read(input longint raddr, output longint rdata);
	import "DPI-C" function void mpmem_write(input longint waddr, input longint wdata, input byte wmask);
	always @(*) begin
		if(lm_en)begin
			case(funct3)
			  3'b001 :
			    begin mpmem_read(maddr, mrdata); 
		                  mrdata = {{48{mrdata[15]}},mrdata[15:0]};
			    end
			  3'b010 :
			    begin mpmem_read(maddr, mrdata); 
		                  mrdata = {{32{mrdata[31]}},mrdata[31:0]};
			    end
			  3'b011 : mpmem_read(maddr, mrdata);
			  3'b100 :
			    begin mpmem_read(maddr, mrdata); //lbu
		                  mrdata = {{56{1'b0}},mrdata[7:0]};
			    end
			  3'b101 :
			    begin mpmem_read(maddr, mrdata); 
		                  mrdata = {{48{1'b0}},mrdata[15:0]};
			    end
		  	  default mrdata = 0;
			endcase
		end
		else if(sm_en)begin
			mrdata = 0;
	      		case(funct3)
				3'b000 : mpmem_write(maddr, mwdata, 8'h01);//sb
				3'b001 : mpmem_write(maddr, mwdata, 8'h03);//sh
				3'b010 : mpmem_write(maddr, mwdata, 8'h0f);//sw
				3'b011 : mpmem_write(maddr, mwdata, 8'hff);//sd 
				default : mpmem_write(maddr, mwdata, 8'b00000000);
			endcase
		end
		else mrdata = 0;
	end
 endmodule
